<template>
  <div>
    <el-form ref="form" label-width="150px" v-loading="load">
      <template v-if="threeLevelsbool.haiSetquan">
        <div class="setTitle">设置公海开放权限</div>
        <el-form-item label="设置团队" style="width: 50%">
          <el-cascader :key="KAIteamVal_key.length" v-model="KAIteamVal" style="width: 100%" :options="teamsArr"
                       :props="{ multiple: true, checkStrictly: true }" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="设置个人" style="width: 50%">
          <el-select v-model="KAIpersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
            <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
      </template>

      <div class="setTitle">设置各种情况下的自动掉入时间</div>
      <el-form-item label="多久未跟进">
        <el-col :span="6">
          <el-input v-model="GENtime">
            <template slot="append">天</template>
          </el-input>
        </el-col>
        <el-col :span="15">
          <el-radio-group v-model="GENradio">
            <el-radio label="0">根据分配时间开始计算</el-radio>
            <el-radio label="1">根据跟进时间开始计算</el-radio>
          </el-radio-group>
        </el-col>
      </el-form-item>
      <template v-for="(item, i) in GENArr">
        <el-form-item label="不受限制筛选条件">
          <el-col :span="6">
            <el-select v-model="item.T_OneVal" placeholder="请选择" @change="ScreenThreeChange('GEN', i)">
              <el-option v-for="item in T_OneArr" :label="item.label" :value="item.type"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_TwoVal" placeholder="请选择">
              <el-option label="等于" value="1"></el-option>
              <el-option label="不等于" value="2"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_ThreeVal" multiple placeholder="请选择">
              <el-option v-for="e in item.T_ThreeArr" :label="e.name" :value="e.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="1">
            <el-button type="danger" icon="el-icon-delete" circle @click="removeCondition('GEN', i)"></el-button>
          </el-col>
        </el-form-item>
      </template>
      <div style="margin: 0 0 20px 150px">
        <el-button type="text" icon="el-icon-plus" @click="addCondition('GEN')">添加 多久未跟进的筛选条件</el-button>
      </div>

      <el-form-item label="多久未邀约">
        <el-col :span="6">
          <el-input v-model="YAOtime">
            <template slot="append">天</template>
          </el-input>
        </el-col>
      </el-form-item>
      <template v-for="(item, i) in YAOArr">
        <el-form-item label="不受限制筛选条件">
          <el-col :span="6">
            <el-select v-model="item.T_OneVal" placeholder="请选择" @change="ScreenThreeChange('YAO', i)">
              <el-option v-for="item in T_OneArr" :label="item.label" :value="item.type"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_TwoVal" placeholder="请选择">
              <el-option label="等于" value="1"></el-option>
              <el-option label="不等于" value="2"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_ThreeVal" multiple placeholder="请选择">
              <el-option v-for="e in item.T_ThreeArr" :label="e.name" :value="e.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="1">
            <el-button type="danger" icon="el-icon-delete" circle @click="removeCondition('YAO', i)"></el-button>
          </el-col>
        </el-form-item>
      </template>
      <div style="margin: 0 0 20px 150px">
        <el-button type="text" icon="el-icon-plus" @click="addCondition('YAO')">添加 多久未邀约的筛选条件</el-button>
      </div>

      <el-form-item label="多久未上门">
        <el-col :span="6">
          <el-input v-model="SHANGtime">
            <template slot="append">天</template>
          </el-input>
        </el-col>
      </el-form-item>

      <template v-for="(item, i) in SHANGArr">
        <el-form-item label="不受限制筛选条件">
          <el-col :span="6">
            <el-select v-model="item.T_OneVal" placeholder="请选择" @change="ScreenThreeChange('SHANG', i)">
              <el-option v-for="item in T_OneArr" :label="item.label" :value="item.type"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_TwoVal" placeholder="请选择">
              <el-option label="等于" value="1"></el-option>
              <el-option label="不等于" value="2"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_ThreeVal" multiple placeholder="请选择">
              <el-option v-for="e in item.T_ThreeArr" :label="e.name" :value="e.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="1">
            <el-button type="danger" icon="el-icon-delete" circle @click="removeCondition('SHANG', i)"></el-button>
          </el-col>
        </el-form-item>
      </template>

      <div style="margin: 0 0 20px 150px">
        <el-button type="text" icon="el-icon-plus" @click="addCondition('SHANG')">添加 多久未上门的筛选条件</el-button>
      </div>

      <el-form-item label="多久未签约">
        <el-col :span="6">
          <el-input v-model="QIANtime">
            <template slot="append">天</template>
          </el-input>
        </el-col>
      </el-form-item>
      <template v-for="(item, i) in QIANArr">
        <el-form-item label="不受限制筛选条件">
          <el-col :span="6">
            <el-select v-model="item.T_OneVal" placeholder="请选择" @change="ScreenThreeChange('QIAN', i)">
              <el-option v-for="item in T_OneArr" :label="item.label" :value="item.type"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_TwoVal" placeholder="请选择">
              <el-option label="等于" value="1"></el-option>
              <el-option label="不等于" value="2"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select v-model="item.T_ThreeVal" multiple placeholder="请选择">
              <el-option v-for="e in item.T_ThreeArr" :label="e.name" :value="e.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="1">
            <el-button type="danger" icon="el-icon-delete" circle @click="removeCondition('QIAN', i)"></el-button>
          </el-col>
        </el-form-item>
      </template>
      <div style="margin: 0 0 20px 150px">
        <el-button type="text" icon="el-icon-plus" @click="addCondition('QIAN')">添加 多久未签约的筛选条件</el-button>
      </div>

      <div class="setTitle">设置重要客户延迟掉入天数</div>
      <el-form-item label="延迟掉入天数">
        <el-col :span="6">
          <el-input v-model="delayNum">
            <template slot="append">天</template>
          </el-input>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="delayFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>

      <div class="setTitle">重复客户再次添加的冷却期</div>
      <el-form-item label="冷却时长">
        <el-col :span="6">
          <el-input v-model="coolingNum">
            <template slot="append">天</template>
          </el-input>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="coolingFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>

      <div class="setTitle">设置捞取上限</div>
      <el-form-item label="捞取上限">
        <el-col :span="6">
          <el-input v-model="fishingNum">
            <template slot="append">条/月</template>
          </el-input>
        </el-col>
        <el-col :span="1">
          <el-tooltip class="item" effect="dark" content="每月月初0点更新" placement="top-start">
            <i class="el-icon-warning-outline" style="color:#F56C6C"></i>
          </el-tooltip>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="fishingFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>
      <el-form-item label="指定受限团队" style="width: 50%">
        <el-cascader :key="fishingTeamVal_key.length" v-model="fishingTeamVal" style="width: 100%" :options="teamsArr"
                     :props="{ multiple: true, checkStrictly: true }" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="指定受限个人" style="width: 50%">
        <el-select v-model="fishingPersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
          <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>

      <div class="setTitle">设置可拥有的客户上限 （客户上限 = 我的客户 + 再分配客户 + 重要客户 + 今日待办）</div>
      <el-form-item label="可拥有客户上限">
        <el-col :span="6">
          <el-input v-model="uplimitNum">
            <template slot="append">条</template>
          </el-input>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="uplimitFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>
      <el-form-item label="指定受限团队" style="width: 50%">
        <el-cascader :key="uplimitTeamVal_key.length" v-model="uplimitTeamVal" style="width: 100%" :options="teamsArr"
                     :props="{ multiple: true, checkStrictly: true }" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="指定受限个人" style="width: 50%">
        <el-select v-model="uplimitPersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
          <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>

      <div class="setTitle">设置列表字段加密</div>
      <el-form-item label="列表加密字段">
        <el-col :span="6">
          <el-select v-model="encryptionVal" multiple placeholder="请选择">
            <el-option v-for="item in encryptionArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
          </el-select>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="encryptionFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>
      <el-form-item label="指定受限团队" style="width: 50%">
        <el-cascader :key="encryptionTeamVal_key.length" v-model="encryptionTeamVal" style="width: 100%" :options="teamsArr"
                     :props="{ multiple: true, checkStrictly: true }" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="指定受限个人" style="width: 50%">
        <el-select v-model="encryptionPersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
          <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>

      <div class="setTitle">设置禁止查看客户详情</div>
      <el-form-item label="禁止查看客户详情">
        <el-col :span="2">
          <el-switch v-model="prohibitVal" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="prohibitFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>
      <el-form-item label="指定受限团队" style="width: 50%">
        <el-cascader :key="prohibitTeamVal_key.length" v-model="prohibitTeamVal" style="width: 100%" :options="teamsArr"
                     :props="{ multiple: true, checkStrictly: true }" clearable></el-cascader>
      </el-form-item>
      <el-form-item label="指定受限个人" style="width: 50%">
        <el-select v-model="prohibitPersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
          <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>

      <div class="setTitle">设置跟进记录查看权限</div>
      <el-form-item label="跟进记录查看权限">
        <el-col :span="6">
          <el-select v-model="followVal" placeholder="请选择">
            <el-option label="仅自己" value="1"></el-option>
            <el-option label="所有记录" value="2"></el-option>
          </el-select>
        </el-col>
        <el-col :span="1">
          <el-checkbox v-model="followFlg" true-label="1" false-label="0">（选中后该项设置生效）</el-checkbox>
        </el-col>
      </el-form-item>
      <template v-if="followVal == '2'">
        <div class="setTitle">指定可查看 所有记录 的人员</div>
        <el-form-item label="指定人员" style="width: 50%">
          <el-select v-model="followPersonalVal" multiple filterable placeholder="请选择" style="width: 100%">
            <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
      </template>
      <template v-if="followVal == '2'">
        <div class="setTitle">指定可查看 所有记录（包含掉入记录） 的人员</div>
        <el-form-item label="指定人员" style="width: 50%">
          <el-select v-model="followPersonalSuoVal" multiple filterable placeholder="请选择" style="width: 100%">
            <el-option v-for="item in personalArr" :key="item.id" :label="item.label" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
      </template>

      <el-form-item>
        <el-button type="primary" @click="subForm">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {
  InternationalWatersSetInit,
  InternationalWatersSetTeamData,
  InternationalWatersSetUserData,
  InternationalWatersSetEncryptionData,
  InternationalWatersSetScreenData,
  InternationalWatersSetScreenThreeData,
  InternationalWatersSetFormSubAjax,
  idHome
} from '../../../../api/index';
import array_search from '../../../../utils/arrIndex';
export default {
  data() {
    return {
      //当前编辑公海id
      HAI_ID: "",
      //组件load
      load: false,
      //团队数据
      teamsArr: [
        {
          value: 1,
          label: '代代平台',
          children: [
            {
              value: 2,
              label: '销售一部',
              children: [
                {
                  value: 4,
                  label: '飞虎队'
                }
              ]
            },
            {
              value: 3,
              label: '销售二部'
            }
          ]
        }
      ],
      //个人数据
      personalArr: [
        {
          id: '1',
          label: '哪吒'
        },
        {
          id: '2',
          label: '三太子'
        },
        {
          id: '3',
          label: '东海龙王'
        },
        {
          id: '4',
          label: '东皇'
        }
      ],
      //公海开放权限
      KAIteamVal: [],
      KAIteamVal_key: [],
      KAIpersonalVal: [],
      //自动掉入
      T_OneArr: [
        {
          id: '1',
          label: '客户等级'
        },
        {
          id: '2',
          label: '创建人'
        },
        {
          id: '3',
          label: '来源'
        }
      ],
      GENtime: '3',
      GENArr: [],
      GENradio: '0',
      YAOtime: '3',
      YAOArr: [],
      SHANGtime: '3',
      SHANGArr: [],
      QIANtime: '3',
      QIANArr: [],
      //延迟掉入
      delayNum: '1',
      delayFlg: '0',
      //冷却时长
      coolingNum: '30',
      coolingFlg: '0',
      //捞取
      fishingNum: '100',
      fishingFlg: '0',
      fishingTeamVal: [],
      fishingTeamVal_key: [],
      fishingPersonalVal: [],
      //上限
      uplimitNum: '500',
      uplimitFlg: '0',
      uplimitTeamVal: [],
      uplimitTeamVal_key: [],
      uplimitPersonalVal: [],
      //加密
      encryptionVal: [],
      encryptionFlg: '0',
      encryptionArr: [],
      encryptionTeamVal: [],
      encryptionTeamVal_key: [],
      encryptionPersonalVal: [],
      //禁止
      prohibitVal: false,
      prohibitFlg: '0',
      prohibitTeamVal: [],
      prohibitTeamVal_key: [],
      prohibitPersonalVal: [],
      //跟进记录
      followVal: '',
      followFlg: '0',
      followPersonalVal: [],
      followPersonalSuoVal: [],
    };
  },
  props: ["activeIndexId", 'threeLevelsbool'],
  created() {
    if (this.activeIndexId) {
      this.HAI_ID = this.activeIndexId;
      this.teamAjax();

      this.encryptionAjax();
      this.ScreenAjax();
    }
  },
  methods: {
    //初始化设置信息
    getInit() {
      InternationalWatersSetInit({ seasId: this.HAI_ID })
        .then((res) => {
          this.load = false;
          if (res.code === 0) {
            //公海开放权限
            // this.KAIteamVal = JSON.parse(res.openPermission.teamArr ? res.openPermission.teamArr : []);
            if (res.openPermission.filterTeamList) {
              this.KAIteamVal = [];
              this.KAIteamVal_key = [];
              res.openPermission.filterTeamList.forEach((item, i) => {
                this.idpostion(item, this.KAIteamVal, this.KAIteamVal_key);
              })
            } else {
              this.KAIteamVal = [];
              this.KAIteamVal_key = [];
            }
            this.KAIpersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.openPermission.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            //跟进
            this.GENtime = res.notFollowedUp.hscValue ? res.notFollowedUp.hscValue : this.GENtime;
            this.GENradio = res.notFollowedUp.hscChecked ? res.notFollowedUp.hscChecked : this.GENradio;
            this.GENArr = (() => {
              let arr = [];
              res.notFollowedUp.filterConditionList.forEach((item, i) => {
                arr.push({
                  T_OneVal: item.filterCondition.fcType,
                  T_TwoVal: item.fccEqualsType,
                  T_ThreeVal: (() => {
                    let l_arr = [];
                    item.filterConditionValueList.forEach((e, index) => {
                      l_arr.push(e.fcvValue);
                    });
                    return l_arr;
                  })(),
                  T_ThreeArr: item.valueList
                });
              });
              return arr;
            })();
            //邀约
            this.YAOtime = res.notInvited.hscValue ? res.notInvited.hscValue : this.YAOtime;
            this.YAOArr = (() => {
              let arr = [];
              res.notInvited.filterConditionList.forEach((item, i) => {
                arr.push({
                  T_OneVal: item.filterCondition.fcType,
                  T_TwoVal: item.fccEqualsType,
                  T_ThreeVal: (() => {
                    let l_arr = [];
                    item.filterConditionValueList.forEach((e, index) => {
                      l_arr.push(e.fcvValue);
                    });
                    return l_arr;
                  })(),
                  T_ThreeArr: item.valueList
                });
              });
              return arr;
            })();
            //上门
            this.SHANGtime = res.notComing.hscValue ? res.notComing.hscValue : this.SHANGtime;
            this.SHANGArr = (() => {
              let arr = [];
              res.notComing.filterConditionList.forEach((item, i) => {
                arr.push({
                  T_OneVal: item.filterCondition.fcType,
                  T_TwoVal: item.fccEqualsType,
                  T_ThreeVal: (() => {
                    let l_arr = [];
                    item.filterConditionValueList.forEach((e, index) => {
                      l_arr.push(e.fcvValue);
                    });
                    return l_arr;
                  })(),
                  T_ThreeArr: item.valueList
                });
              });
              return arr;
            })();
            //签约
            this.QIANtime = res.notSigned.hscValue ? res.notSigned.hscValue : this.QIANtime;
            this.QIANArr = (() => {
              let arr = [];
              res.notSigned.filterConditionList.forEach((item, i) => {
                arr.push({
                  T_OneVal: item.filterCondition.fcType,
                  T_TwoVal: item.fccEqualsType,
                  T_ThreeVal: (() => {
                    let l_arr = [];
                    item.filterConditionValueList.forEach((e, index) => {
                      l_arr.push(e.fcvValue);
                    });
                    return l_arr;
                  })(),
                  T_ThreeArr: item.valueList
                });
              });
              return arr;
            })();
            //延迟掉入
            this.delayNum = res.daysOfDelayedDropIn.hscValue ? res.daysOfDelayedDropIn.hscValue : this.delayNum;
            this.delayFlg = res.daysOfDelayedDropIn.hscChecked;
            //冷却时长
            this.coolingNum = res.customersDoubleSave.hscValue ? res.customersDoubleSave.hscValue : this.coolingNum;
            this.coolingFlg = res.customersDoubleSave.hscChecked;
            //捞取
            this.fishingNum = res.takeTheUpperLimit.hscValue ? res.takeTheUpperLimit.hscValue : this.fishingNum;
            this.fishingFlg = res.takeTheUpperLimit.hscChecked;
            // this.fishingTeamVal = JSON.parse(res.takeTheUpperLimit.teamArr ? res.takeTheUpperLimit.teamArr : []);
            if (res.takeTheUpperLimit.filterTeamList) {
              this.fishingTeamVal = [];
              this.fishingTeamVal_key = [];
              res.takeTheUpperLimit.filterTeamList.forEach((item, i) => {
                this.idpostion(item, this.fishingTeamVal, this.fishingTeamVal_key);
              })
            } else {
              this.fishingTeamVal = [];
              this.fishingTeamVal_key = [];
            }
            // this.fishingPersonalVal = res.takeTheUpperLimit.filterUserList;
            this.fishingPersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.takeTheUpperLimit.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            //上限
            this.uplimitNum = res.haveCustomersCap.hscValue ? res.haveCustomersCap.hscValue : this.uplimitNum;
            this.uplimitFlg = res.haveCustomersCap.hscChecked;
            // this.uplimitTeamVal = JSON.parse(res.haveCustomersCap.teamArr ? res.haveCustomersCap.teamArr : []);
            if (res.haveCustomersCap.filterTeamList) {
              this.uplimitTeamVal = [];
              this.uplimitTeamVal_key = [];
              res.haveCustomersCap.filterTeamList.forEach((item, i) => {
                this.idpostion(item, this.uplimitTeamVal, this.uplimitTeamVal_key);
              })
            } else {
              this.uplimitTeamVal = [];
              this.uplimitTeamVal_key = [];
            }
            // this.uplimitPersonalVal = res.haveCustomersCap.filterUserList;
            this.uplimitPersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.haveCustomersCap.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            //加密
            this.encryptionVal = res.fieldEncryption.encryptionProperties;
            this.encryptionFlg = res.fieldEncryption.hscChecked;
            // this.encryptionTeamVal = JSON.parse(res.fieldEncryption.teamArr ? res.fieldEncryption.teamArr : []);
            if (res.fieldEncryption.filterTeamList) {
              this.encryptionTeamVal = [];
              this.encryptionTeamVal_key = [];
              res.fieldEncryption.filterTeamList.forEach((item, i) => {
                this.idpostion(item, this.encryptionTeamVal, this.encryptionTeamVal_key);
              })
            } else {
              this.encryptionTeamVal = [];
              this.encryptionTeamVal_key = [];
            }
            // this.encryptionPersonalVal = res.fieldEncryption.filterUserList;
            this.encryptionPersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.fieldEncryption.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            //禁止
            this.prohibitVal = res.stopCustomersInfo.hscValue == '1' ? true : false;
            this.prohibitFlg = res.stopCustomersInfo.hscChecked;
            // this.prohibitTeamVal = JSON.parse(res.stopCustomersInfo.teamArr ? res.stopCustomersInfo.teamArr : []);
            if (res.stopCustomersInfo.filterTeamList) {
              this.prohibitTeamVal = [];
              this.prohibitTeamVal_key = [];
              res.stopCustomersInfo.filterTeamList.forEach((item, i) => {
                this.idpostion(item, this.prohibitTeamVal, this.prohibitTeamVal_key);
              })
            } else {
              this.prohibitTeamVal = [];
              this.prohibitTeamVal_key = [];
            }
            // this.prohibitPersonalVal = res.stopCustomersInfo.filterUserList;
            this.prohibitPersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.stopCustomersInfo.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            //跟进记录
            this.followVal = res.followedUpRecord.hscValue;
            this.followFlg = res.followedUpRecord.hscChecked;
            // this.followPersonalVal = res.followedUpRecord.filterUserList;
            this.followPersonalVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.followedUpRecord.filterUserList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();
            // this.followPersonalSuoVal = res.followedUpRecord.filterTeamList;
            this.followPersonalSuoVal = (() => {
              let arr = [];
              this.personalArr.forEach((item, i) => {
                res.followedUpRecord.filterTeamList.forEach((e, index) => {
                  if (item.id == e) {
                    arr.push(e);
                  }
                })
              })
              return arr;
            })();

          } else {
            this.$message(res.msg);
          }
        })
        .catch((res) => {
          console.log(res);
        });
    },
    //id定位多维
    idpostion(id, item, key) {
      idHome({ targetId: id, findTeamList: this.teamsArr }).then((res) => {
        if (res.code === 0) {
          item.push(res.route);
          key.push(res.route);
        }
      })
    },
    //初始化团队数据结构
    teamAjax() {
      this.load = true;
      this.teamsArr = [];
      InternationalWatersSetTeamData().then((res) => {
        if (res.code === 0) {
          res.teamList.forEach((item, i) => {
            this.teamsArr.push({
              value: item.id,
              label: item.name
            });
            if (item.childTeam.length > 0) {
              this.teamsArr[i].children = [];
              this.teamAjaxData(item, this.teamsArr[i].children);
            }
          });
          this.userAjax();
        } else {
          this.$message(res.msg);
        }
      });
    },
    //初始化团队数据结构
    teamAjaxData(item, msg) {
      item.childTeam.forEach((e, i) => {
        msg.push({
          value: e.id,
          label: e.name
        });
        if (e.childTeam.length > 0) {
          msg[i].children = [];
          this.teamAjaxData(e, msg[i].children);
        }
      });
    },
    //初始化个人数据结构
    userAjax() {
      this.personalArr = [];
      InternationalWatersSetUserData().then((res) => {
        if (res.code === 0) {
          res.userList.forEach((item, i) => {
            this.personalArr.push({
              id: item.id,
              label: item.name
            });
          });
          //数据回来响应初始化
          this.getInit();
        } else {
          this.$message(res.msg);
        }
      });
    },
    //初始化加密字段数据结构
    encryptionAjax() {
      this.encryptionArr = [];
      InternationalWatersSetEncryptionData().then((res) => {
        if (res.code === 0) {
          res.properties.forEach((item, i) => {
            this.encryptionArr.push({
              id: item.properties,
              label: item.name
            });
          });
        } else {
          this.$message(res.msg);
        }
      });
    },
    //初始化筛选条件下拉数据结构
    ScreenAjax() {
      this.T_OneArr = [];
      InternationalWatersSetScreenData().then((res) => {
        if (res.code === 0) {
          res.conditions.forEach((item, i) => {
            this.T_OneArr.push({
              id: item.fcId,
              type: item.fcType,
              label: item.fcName
            });
          });
        } else {
          this.$message(res.msg);
        }
      });
    },
    //选择筛选条件change
    ScreenThreeChange(str, i) {
      let val;
      if (str == 'GEN') {
        val = this.GENArr[i].T_OneVal;
      } else if (str == 'YAO') {
        val = this.YAOArr[i].T_OneVal;
      } else if (str == 'SHANG') {
        val = this.SHANGArr[i].T_OneVal;
      } else if (str == 'QIAN') {
        val = this.QIANArr[i].T_OneVal;
      }
      InternationalWatersSetScreenThreeData({ conditionType: val }).then((res) => {
        if (res.code === 0) {
          if (str == 'GEN') {
            this.GENArr[i].T_ThreeArr = res.values;
          } else if (str == 'YAO') {
            this.YAOArr[i].T_ThreeArr = res.values;
          } else if (str == 'SHANG') {
            this.SHANGArr[i].T_ThreeArr = res.values;
          } else if (str == 'QIAN') {
            this.QIANArr[i].T_ThreeArr = res.values;
          }
        } else {
          this.$message(res.msg);
        }
      });
    },
    //添加筛选条件
    addCondition(str) {
      if (str == 'GEN') {
        this.GENArr.push({
          T_OneVal: '',
          T_TwoVal: '',
          T_ThreeVal: '',
          T_ThreeArr: []
        });
      } else if (str == 'YAO') {
        this.YAOArr.push({
          T_OneVal: '',
          T_TwoVal: '',
          T_ThreeVal: '',
          T_ThreeArr: []
        });
      } else if (str == 'SHANG') {
        this.SHANGArr.push({
          T_OneVal: '',
          T_TwoVal: '',
          T_ThreeVal: '',
          T_ThreeArr: []
        });
      } else if (str == 'QIAN') {
        this.QIANArr.push({
          T_OneVal: '',
          T_TwoVal: '',
          T_ThreeVal: '',
          T_ThreeArr: []
        });
      }
    },
    //删除筛选条件
    removeCondition(str, i) {
      if (str == 'GEN') {
        this.GENArr.splice(i, 1);
      } else if (str == 'YAO') {
        this.YAOArr.splice(i, 1);
      } else if (str == 'SHANG') {
        this.SHANGArr.splice(i, 1);
      } else if (str == 'QIAN') {
        this.QIANArr.splice(i, 1);
      }
    },
    //提交设置
    subForm() {
      this.load = true;
      let obj = {
        seasId: this.HAI_ID,
        openPermission: {
          type: '0',
          teamList: ((that) => {
            let arr = [];
            that.KAIteamVal.forEach((item, i) => {
              arr.push(item[item.length - 1]);
            });
            return arr;
          })(this),
          teamArr: JSON.stringify(this.KAIteamVal),
          userList: this.KAIpersonalVal
        },
        notFollowedUp: {
          type: '1',
          filterConditionAndValueList: ((that) => {
            let arr = [];
            // T_OneArr
            that.GENArr.forEach((item, i) => {
              arr.push({
                conditionId: (() => {
                  let id;
                  this.T_OneArr.forEach((e, index) => {
                    if (item.T_OneVal === e.type) {
                      id = e.id;
                    }
                  });
                  return id;
                })(),
                equalsType: item.T_TwoVal,
                value: item.T_ThreeVal
              });
            });
            return arr;
          })(this),
          configValue: this.GENtime,
          isChecked: this.GENradio
        },
        notInvitation: {
          type: '2',
          filterConditionAndValueList: ((that) => {
            let arr = [];
            that.YAOArr.forEach((item, i) => {
              arr.push({
                conditionId: (() => {
                  let id;
                  this.T_OneArr.forEach((e, index) => {
                    if (item.T_OneVal === e.type) {
                      id = e.id;
                    }
                  });
                  return id;
                })(),
                equalsType: item.T_TwoVal,
                value: item.T_ThreeVal
              });
            });
            return arr;
          })(this),
          configValue: this.YAOtime
        },
        notComing: {
          type: '3',
          filterConditionAndValueList: ((that) => {
            let arr = [];
            that.SHANGArr.forEach((item, i) => {
              arr.push({
                conditionId: (() => {
                  let id;
                  this.T_OneArr.forEach((e, index) => {
                    if (item.T_OneVal === e.type) {
                      id = e.id;
                    }
                  });
                  return id;
                })(),
                equalsType: item.T_TwoVal,
                value: item.T_ThreeVal
              });
            });
            return arr;
          })(this),
          configValue: this.SHANGtime
        },
        notSigned: {
          type: '4',
          filterConditionAndValueList: ((that) => {
            let arr = [];
            that.QIANArr.forEach((item, i) => {
              arr.push({
                conditionId: (() => {
                  let id;
                  this.T_OneArr.forEach((e, index) => {
                    if (item.T_OneVal === e.type) {
                      id = e.id;
                    }
                  });
                  return id;
                })(),
                equalsType: item.T_TwoVal,
                value: item.T_ThreeVal
              });
            });
            return arr;
          })(this),
          configValue: this.QIANtime
        },
        delayedDropIn: {
          type: '5',
          configValue: this.delayNum,
          isChecked: this.delayFlg
        },
        doubleSaveDays: {
          type: '6',
          configValue: this.coolingNum,
          isChecked: this.coolingFlg
        },
        takUpperLimit: {
          type: '7',
          userList: this.fishingPersonalVal,
          teamList: ((that) => {
            let arr = [];
            that.fishingTeamVal.forEach((item, i) => {
              arr.push(item[item.length - 1]);
            });
            return arr;
          })(this),
          teamArr: JSON.stringify(this.fishingTeamVal),
          configValue: this.fishingNum,
          isChecked: this.fishingFlg
        },
        haveCustomersCap: {
          type: '8',
          userList: this.uplimitPersonalVal,
          teamList: ((that) => {
            let arr = [];
            that.uplimitTeamVal.forEach((item, i) => {
              arr.push(item[item.length - 1]);
            });
            return arr;
          })(this),
          teamArr: JSON.stringify(this.uplimitTeamVal),
          configValue: this.uplimitNum,
          isChecked: this.uplimitFlg
        },
        fieldEncryption: {
          type: '9',
          userList: this.encryptionPersonalVal,
          teamList: ((that) => {
            let arr = [];
            that.encryptionTeamVal.forEach((item, i) => {
              arr.push(item[item.length - 1]);
            });
            return arr;
          })(this),
          teamArr: JSON.stringify(this.encryptionTeamVal),
          isChecked: this.encryptionFlg,
          properties: ((that) => {
            let arr = [];
            this.encryptionArr.forEach((item, i) => {
              this.encryptionVal.forEach((e, index) => {
                if (item.id === e) {
                  arr.push({
                    name: item.label,
                    properties: item.id
                  });
                }
              });
            });
            return arr;
          })(this)
        },
        stopCustomersInfo: {
          type: '10',
          userList: this.prohibitPersonalVal,
          teamList: ((that) => {
            let arr = [];
            that.prohibitTeamVal.forEach((item, i) => {
              arr.push(item[item.length - 1]);
            });
            return arr;
          })(this),
          teamArr: JSON.stringify(this.prohibitTeamVal),
          configValue: this.prohibitVal ? '1' : '0',
          isChecked: this.prohibitFlg
        },
        followedUpRecord: {
          type: '11',
          userList: this.followPersonalVal,
          teamList: this.followPersonalSuoVal,
          configValue: this.followVal,
          isChecked: this.followFlg
        }
      };
      InternationalWatersSetFormSubAjax(obj).then((res) => {
        this.load = false;
        if (res.code === 0) {
          this.$message.success('设置成功');
        } else {
          this.$message(res.msg);
        }
      });
    }
  }
};
</script>
<style scoped>
.setTitle {
    font-size: 12px;
    color: #999;
    margin-bottom: 15px;
}
</style>